import { createRouter, createWebHistory } from 'vue-router'
import store from '../store'

const router = createRouter({
  history: createWebHistory(),     //路由模式
  routes: [
    {
      name: 'login',
      path: '/login',
      component: () => import('@/views/login/index.vue'),
      meta: {
        title: "登录",
        icon: "avatar",
        hidden: true
      },
    },
    {
      name: 'lock',
      path: '/lock',
      component: () => import('@/views/login/lock.vue'),
      meta: {
        title: "锁定",
        icon: "avatar",
        hidden: true
      },
    },
    {
      name: '404',
      path: '/404',
      component: () => import('@/views/error/404.vue'),
      meta: {
        title: "404",
        icon: "avatar",
        hidden: true
      },
    },
    {
      path: '/:pathMatch(.*)',
      redirect: '/404',
      meta: {
        title: "404",
        hidden: true
      },
    },


    {
      name: 'home',
      path: '/',
      redirect: "home",
      component: () => import('@/components/layout/index.vue'),
      meta: {
        title: "系统管理",
        icon: "Film",
      },
      children: [
        {
          path: '/home',
          name: 'homePage',
          component: () => import('@/views/home/index.vue'),
          meta: {
            title: "主页",
            icon: "Shop"
          },
        },
        {
          name: '404',
          path: '/404',
          component: () => import('@/views/error/404.vue'),
          meta: {
            title: "404",
            icon: "avatar",
            hidden: true
          },
        },
        {
          path: '/:pathMatch(.*)',
          redirect: '/404',
          meta: {
            title: "404",
            hidden: true
          },
        },
        {
          path: 'home',
          name: 'homePage',
          component: () => import('@/views/home/index.vue'),
          meta: {
            title: "仪表盘",
            icon: "CreditCard",
            hidden: true
          },
        },
        {
          path: 'user',
          name: 'user',
          component: () => import('@/views/user/index.vue'),
          meta: {
            title: "用户管理",
            icon: "avatar"
          },
        },
        {
          path: 'role',
          name: 'role',
          component: () => import('@/views/role/index.vue'),
          meta: {
            title: "角色管理",
            icon: "ChatDotSquare"
          },
        },
        {
          path: 'tenant',
          name: 'tenant',
          component: () => import('@/views/tenant/index.vue'),
          meta: {
            title: "租户管理",
            icon: "HotWater"
          },
        },
        {
          path: 'menu',
          name: 'menu',
          component: () => import('@/views/menu/index.vue'),
          meta: {
            title: "菜单管理",
            icon: "ChatDotSquare"
          },
        },
        {
          path: 'userCenter',
          name: 'userCenter',
          component: () => import('@/views/user/center.vue'),
          meta: {
            title: "用户中心",
            icon: "ChatDotSquare"
          },
        },
      ]
    },
  ]

})

// 路由前置导航
router.beforeEach((tom,from,next)=>{
  let token = localStorage.getItem("token");
  if(token && store.state.menus.length == 0){
  }
  next()
})

export default router      //导出